package com.book_manager.servlets.LAndR;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.book_manager.entity.LAndR;
import com.book_manager.service.LAndRService;

/**
 * Servlet implementation class ResetPasswordServlet
 */
@WebServlet("/ResetPassword")
public class ResetPasswordServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ResetPasswordServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		String ResetName=request.getParameter("resetName");
		String ResetPassword=request.getParameter("resetPassword");
		int loginNum=Integer.parseInt(request.getParameter("loginNum"));
		LAndR l=new LAndR(ResetName,ResetPassword,loginNum);
		LAndRService ls=new LAndRService();
		int loginNumber=0;
		if(ls.findUserByUserName(ResetName)!=null) {
			 loginNumber=ls.findUserByUserName(ResetName).getLoginNum();
		}	
		boolean result=ls.ResetUser(l);
		if(loginNum==loginNumber) {	
			if(result){
				response.getWriter().write("resetsucess");
			}
		}else {
			if(result==false){
				response.getWriter().write("resetfail");
			}else{
				response.getWriter().write("loginNumfail");
			}
			
		}
		
		
	}

}
